import Vue from 'vue'
import App from './App'

import store from './store/store.js'
import {$http} from '@escook/request-miniprogram'
uni.$http = $http
$http.baseUrl = 'https://api-hmugo-web.itheima.net'
$http.beforeRequest = function(options) {
	uni.showLoading({
		title: '等着...'
	})
	if(options.url.indexOf('/my/') != -1 ) {
		options.header.Authorization = JSON.stringify(store.state.m_user.token)
	}
}
$http.afterRequest = function(res) {
	uni.hideLoading()
	if(res.data.meta.status >= 200 && res.data.meta.status < 300) {
		uni.showToast({
			title:'请求成功',
			icon:'none'
		})
	}else {
		uni.showToast({
			title:'请求数据失败!',
			icon:'error'
		})
	}
}

// 封装全局提示函数
uni.$showMsg = function(title="操作成功", icon="none", duration=2000) {
	uni.showToast({
		title: title,
		icon: icon,
		duration: duration
	})
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
    ...App,
	store
})
app.$mount()
